package com.ctshk.sapp.finance.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.finance.dto.advance.AdvancePaymentApplyDTO;
import com.ctshk.rpc.finance.dto.advance.AdvancePaymentApplyListDTO;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentApplyAddReq;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentApplyIdReq;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentApplyListReq;
import com.ctshk.rpc.finance.req.advance.AdvancePaymentApprovalReq;
import com.ctshk.rpc.finance.req.bill.RollBackReq;
import com.ctshk.rpc.finance.service.IFinanceAdvancePaymentApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 财务预收款申请记录 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-26
 */
@RestController
@RequestMapping("/finance-advance-payment-apply")
@Api(value = "预收申请", tags = "预收申请")
public class FinanceAdvancePaymentApplyController extends BaseController {

    @DubboReference
    private IFinanceAdvancePaymentApplyService advancePaymentApplyService;

    @ApiOperation(value = "列表", notes = "预收管理-查看-申请记录（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "预收款列表", operDesc = "预收款列表")
    @PostMapping("/list")
    public Result<PageResponse<AdvancePaymentApplyListDTO>> list(@RequestBody @Valid AdvancePaymentApplyListReq req) {
        return advancePaymentApplyService.list(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "申请", notes = "申请预收款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.ADD, operTitle = "申请预收款", operDesc = "申请预收款")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid AdvancePaymentApplyAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentApplyService.add(req);
    }

    @ApiOperation(value = "详情", notes = "详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "预收款详情", operDesc = "预收款详情")
    @PostMapping("/detail")
    public Result<AdvancePaymentApplyDTO> detail(@RequestBody @Valid AdvancePaymentApplyIdReq req) {
        return advancePaymentApplyService.detail(req);
    }

    @ApiOperation(value = "审批", notes = "审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "审批预收款", operDesc = "审批预收款")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid AdvancePaymentApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentApplyService.approval(req);
    }

    @ApiOperation(value = "撤回审批", notes = "撤回审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "撤回申请预收款审批", operDesc = "撤回申请预收款审批")
    @PostMapping("/roll-back")
    public Result rollBack(@RequestBody @Valid RollBackReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return advancePaymentApplyService.rollBack(req);
    }

}
